﻿using IdentityServer4.EntityFramework.DbContexts;
using IdentityServer4.EntityFramework.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Ids4Review.AuthorizationServer.Data
{
    public class ConfigurationContextSeed
    {
        public async System.Threading.Tasks.Task SeedAsync(ConfigurationDbContext dbContext, IServiceProvider services)
        {
            if (!dbContext.Clients.Any())
            {
               await dbContext.Clients.AddRangeAsync(Config.GetClients() as List<Client>);
            }
            if (!dbContext.ApiResources.Any())
            {
                await dbContext.ApiResources.AddRangeAsync(Config.GetApiResources() as List<ApiResource>);
            }
            if (!dbContext.IdentityResources.Any())
            {
                await dbContext.IdentityResources.AddRangeAsync(Config.GetIdentityResources() as List<IdentityResource>);
            }
            await dbContext.SaveChangesAsync();
        }
    }
}
